DO $$
DECLARE @X INT = 42
DECLARE @Y INT = @X * 2

PRINT @X
PRINT @Y

BEGIN
  DECLARE @INNER INT = @Y - 1
  PRINT @INNER
END

   PRINT @INNER
$$ LANGUAGE 'pltsql'
